package com.fanhao.dllo.soundfm.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.volley.toolbox.NetworkImageView;
import com.fanhao.dllo.soundfm.R;
import com.fanhao.dllo.soundfm.entity.RadioListResult;
import com.fanhao.dllo.soundfm.entity.RadioStationResult;
import com.fanhao.dllo.soundfm.fragment.BaseFragment;
import com.fanhao.dllo.soundfm.utils.CountToOthers;
import com.fanhao.dllo.soundfm.volley.GetBitmap;
import com.fanhao.dllo.soundfm.volley.VolleySingleton;

import java.util.List;

/**
 * Created by dllo on 16/1/21.
 */
public class RadioListAdapter extends RecyclerView.Adapter
        <RadioListAdapter.RadioViewHolder> {
    private Context context;
    private List<RadioListResult.ResultEntity> resultList;

    public RadioListAdapter(Context context) {
        this.context = context;
    }

    public void addResultData(List<RadioListResult.ResultEntity> resultList) {
        this.resultList = resultList;
        notifyDataSetChanged();
    }

    @Override
    public RadioViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context)
                .inflate(R.layout.fragment_radio_list_adapter_item, parent, false);
        return new RadioViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RadioViewHolder holder, int position) {
        if (resultList != null && resultList.size()> 0) {
            holder.titleRadioTv.setText(resultList.get(position).getRname());
            holder.descripRadioTv.setText("正在直播 : "+resultList.get(position).getProgramName());
            holder.playCountsRadioTv.setText(
                    CountToOthers.getCountToWan(resultList.get(position).getRadioPlayCount()));
            holder.radioIv.setImageUrl(resultList.get(position).getRadioCoverLarge(),BaseFragment.getImageLoader());
        }


    }

    @Override
    public int getItemCount() {
        return resultList != null && resultList.size() > 0 ?
                resultList.size() : 0;
    }

    public class RadioViewHolder extends RecyclerView.ViewHolder {
        TextView titleRadioTv,descripRadioTv,playCountsRadioTv;
        NetworkImageView radioIv;
        public RadioViewHolder(View itemView) {
            super(itemView);
            titleRadioTv = (TextView) itemView.findViewById(R.id.tvSubTitle_radioListAdapter);
            descripRadioTv = (TextView) itemView.findViewById(R.id.tvDescrip_radioListAdapter);
            playCountsRadioTv = (TextView) itemView.findViewById(R.id.tvPlayCounts_RadioListAdapter);
            radioIv = (NetworkImageView) itemView.findViewById(R.id.iv_radioListAdapter);


        }
    }
}
